<template>
  <div class="setting-page">
    <!-- 导航栏 -->
    <van-nav-bar
      title="注册账号"
      left-arrow
      @click-left="onClickLeft"
      class="color"
    />

    <!-- 登录表单 -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请输入账号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填输入密码' }]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit" color=" #07c160"
          >注册</van-button
        >
      </div>
    </van-form>

    <!-- 跳转路由 -->
    <router-link class="link" to="/search">已有账号？去登录</router-link>
  </div>
</template>

<script>
import { setting } from "@/api/user.js";

export default {
  name: "setting-page",
  data() {
    return { username: "", password: "" };
  },

  methods: {
    async onSubmit(values) {
      console.log("submit", values);

      const data = await setting(values);
      this.$toast.success("注册成功");
      console.log(data);
    },
  },
};
</script>

<style lang="less" scoped>
.link {
  color: black;
  font-size: 12px;
  padding-right: 39%;
  float: right;
}
.color {
  background-color: #07c160;
}
</style>
